package com.common.basis.util;

import com.common.basis.entity.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;

/**
 * auth跑龙套
 *
 * @author guochaowang
 * @date 2022/06/20
 */
public class AuthUtils {
    public static User getUser() {
        OAuth2Authentication authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
        Authentication userAuthentication = authentication.getUserAuthentication();
        return (User) userAuthentication.getPrincipal();
    }
}
